from tkinter import *
from tkinter.messagebox import *

root = Tk()
root.geometry('500x800')
context = StringVar(value='余奕奕')
# 标签
lable = Label(root,text='余奕奕好帅',bg='green',fg='black',border=1,borderwidth=2,height=5,width=10,padx=10,pady=10)
lable.pack()
# 按钮
button = Button(root,text='提交',activebackground='white',activeforeground='green',bg='green',
                fg='white',borderwidth=10,border=5,height=3,width=10,padx=5,pady=5)
button.pack()
# 复选框
checkbutton1 = Checkbutton(root,textvariable=context,state='disable')
checkbutton2 = Checkbutton(root,text="A")
checkbutton3 = Checkbutton(root,text="B")
checkbutton4 = Checkbutton(root,text="C")
checkbutton1.pack()
checkbutton2.pack()
checkbutton3.pack()
checkbutton4.pack()
# 文本框
entry = Entry(root,show='*')
entry.pack()
# 单选按钮
radiobutton1 = Radiobutton(root,text='余奕奕',value=1)
radiobutton2 = Radiobutton(root,text='嘤嘤嘤',value=2)
radiobutton1.pack()
radiobutton2.pack()
# 列表框
list =Listbox(root,xscrollcommand=10,yscrollcommand=10)
list.insert(1,'pythonafdaaggadfgadfgdfadfadf')
list.insert(2,'yyy')
list.insert(3,'oao')
list.insert(1,'pythonafdaaggadfgadfgdfadfadf')
list.insert(3,'oao')
list.insert(3,'oao')
list.insert(2,'yyy')
list.insert(1,'pythonafdaaggadfgadfgdfadfadf')
list.insert(3,'oao')
list.insert(3,'oao')
list.insert(2,'yyy')
list.insert(3,'oao')
list.insert(1,'pythonafdaaggadfgadfgdfadfadf')
list.pack()
# 文本框
text = Text(root,selectbackground='green',state='disable',height=5)
text.pack()
# command事件处理方式
def change():
    lable.config(text='hello world')
button = Button(root,text='change',command=change)
button.pack()
# bind事件处理方式
def handler(event):
    showinfo('到点了','你好!')
button = Button(root,text='点我呀！')
button.bind('<Button-1>',handler)
button.pack()
# 顶级菜单
menu = Menu(root)
def callback():
    print('this is menu')
for item in ['文件','编辑','视图','格式']:
    menu.add_command(label=item,command=callback)
# root['menu'] = menu
# 下拉菜单
menu = Menu(root)
fmenu = Menu(menu)
for item in ['新建','保存','另存为','关闭']:
    fmenu.add_command(label=item,command=callback)
menu.add_cascade(label='文件',menu=fmenu)
root['menu'] = menu

root.mainloop()